<template>
  <div>
    <a-card class="card-header">
      <a-form-model :model="model">
        <a-row :gutter="24">
          <a-col :span="6">
            <a-form-model-item
              label="库区编号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                disabled
                placeholder="请输入库区编号"
                v-model.trim="model.serialNumber"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>

    <!-- 表格区域 -->
    <a-card class="card-content">
      <a-row :gutter="24">
        <a-col :span="22">
          <a-button type="primary" @click="handleAdd">新建货架区</a-button>
        </a-col>
      </a-row>
      <br />
      <!-- <a-table
        :columns="columns"
        :data-source="tableData"
        :loading="loading"
        :pagination="pagination"
        @change="handleTableChange"
        :rowKey="(record, index) => record.id"
        bordered
      >
        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="handleDetail(record)">详情</a>
        </template>
      </a-table> -->
      <div class="flex flex-wrap flex-a-c">
        <div v-for="record in tableData" :key="record.id" class="locationBox">
          <div class="serialNumber">
            {{ record.serialNumber }}
          </div>
          <div class="location_action">
            <a @click="handleEdit(record)">编辑</a>
            <a @click="handleDetail(record)">详情</a>
          </div>
        </div>
      </div>
      <a-pagination
        @change="handleChange"
        v-if="pagination.total > 0"
        v-model="pagination.current"
        :total="pagination.total"
        show-less-items
      />
    </a-card>
    <!-- 货区弹框 -->
    <WareCargoModal
      :stockAreaId="queryParam.id"
      ref="modalForm"
      @ok="modalFormOk"
    />
  </div>
</template>

<script>
import { columns } from "./components/tableConfig";
import { tableMinxins } from "@/unit/mixins/tableMinxins.js";
// import WareCargoModal from "./components/WareCargoModal.vue";
import api from "@/api/apiServer";

export default {
  components: {  },
  mixins: [tableMinxins],
  data() {
    return {
      columns,
      model: {},
      option: [], // 仓库管理数据源
    };
  },
 mounted() {
    let { id, serialNumber } = this.$route.query;
    if (id && serialNumber) {
      this.queryParam.id = Number(id);
      this.model.serialNumber = serialNumber;
      this.getList();
    }
  },
  methods: {
    // 获取列表数据
    async getList(arg) {
      //加载数据 若传入参数1则加载第一页的内容
      this.loading = true;
      if (arg === 1) {
        this.pagination.current = 1;
      }
      var params = this.getQueryParams();
      const res = await api.StockAreaDetail(params);
      this.tableData = res.data.data;
      this.pagination.total = res.data.total;
      this.loading = false;
    },
    handleChange(page, pageSize) {
      this.pagination.current = page;
      this.pagination.pageNumber = page;
      this.pagination.pageSize = pageSize;
      this.getList();
    },
    modalFormOk() {
      this.getList();
    },
    // 新增
    handleAdd() {
      this.$refs.modalForm.title = "新增";
      this.$refs.modalForm.modalAdd();
    },
    //  编辑
    handleEdit(record) {
      this.$refs.modalForm.title = "编辑";
      this.$refs.modalForm.modalEdit(record);
    },
    handleDetail(record) {
      let { id } = record;
      this.$router.push({
        path: `/warehouse/shelves?shelfAreaId=${id}`,
      });
    },
  },
};
</script>

<style lang="less" scoped>
.card-header {
  margin: 20px 0;
}
.card-content {
  button {
    margin-right: 20px;
  }
}
::v-deep .ant-tree-node-content-wrapper {
  width: 90%;
}
::v-deep .ant-form-item {
  margin-bottom: 0;
}
.locationBox {
  width: 8%;
  height: 300px;
  border: 1px solid #333;
  margin: 1%;
  display: flex;
  align-items: center;
  .serialNumber {
    width: 80%;
    padding-left: 45%;
  }
  .location_action {
    width: 30%;
    display: flex;
    flex-direction: column;
    div {
      // padding: 100px;
      height: 30px;
    }
  }
}
</style>
